<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <title>邀请关注</title>
    <meta name="Keywords" content="关键字,关键字">
    <meta name="description" content="我猜你也需要它，这是我分享的意义" />
    <script src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
    <!--css,js-->
    <style type="text/css">
        *{margin:0px;padding:0px}
        body{font-size:12px;font-family:"微软雅黑";color:#666;background:#f1f1f1;}
        .content{width:100%;margin-top:20px;}
        .content .input{height:50px;line-height:50px;width:100%;border-bottom:1px solid #f1f1f1;background:#fff;overflow:hidden;position:relative;}
        .content .input .left{width:20%;padding-left:10px;text-align:justify;float:left;font-size:1.125rem;color:#333;}
        .content .input .right{float:right;width:calc(80% - 10px);}
        .content .input .right input{border:none;outline:none;width:calc(100% - 20px);padding:0 10px;font-size:1rem;}
        .content .input .right .sex{width:calc(50% - 10px);float:left;font-size:1rem;padding-left:10px;}
        .content .input .right .sex input{width:initial;}
        .btn{width:90%;margin:20px 5% 10px;line-height:40px;border-radius:5px;font-size:1rem;}
        button.btn{background:#45c01a;border:1px solid #7cb342;color:#fff;}
        a.btn{background:#fff;color:#666;text-align:center;text-decoration:none;display:block;}
        .ranking{display:block;width:100%;text-align:center;color:#ccc;}

        .content .input .warning{width:110px;height:30px;background:#fff;position:absolute;top:11px;right:-150px;line-height:30px;color:#f86161;font-size:0.875rem;padding-right:10px;text-align:right;}
        .content .input .warning .fa:before{padding-right:5px;}

        #yy{position:fixed;width:100%;height:100%;top:0;left:0;background:rgba(0,0,0,0.5);display:none;}
        #isTop{position:fixed;width:200px;padding:5px 0;background:rgb(255,202,0);top:-100px;left:calc(50% - 100px);color:#fff;font-size:14px;text-align:center;border-radius:5px;box-shadow:0 0 5px #FFCA00;}
    </style>
    <link href="/css/iCheck/custom.css" rel="stylesheet">
    <link href="/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div class="content">
    <div class="input">
        <div class="left">姓名</div>
        <div class="right">
            <input type="text" placeholder="请输入您的姓名" name="name">
        </div>
        <div class="warning name-war">
        </div>
    </div>
    <div class="input">
        <div class="left">性别</div>
        <div class="right i-checks">
            <div class="sex">
                <span>男</span>
                <input type="radio" name="gender" checked="true" value="0">
            </div>
            <div class="sex">
                <span>女</span>
                <input type="radio" name="gender" value="1">
            </div>
        </div>
    </div>
    <div class="input">
        <div class="left">手机号</div>
        <div class="right">
            <input type="mobile" placeholder="请输入手机号" name="mobile">
        </div>
        <div class="warning tel-war">
        </div>
    </div>
    <div class="input">
        <div class="left">单位名称</div>
        <div class="right">
            <input type="text" placeholder="请输入单位名称" name="unit">
        </div>
        <div class="warning tel-war">
        </div>
    </div>
    <button class="btn btn-success" id="signIn">注册</button>
</div>
<div id="isTop"></div>
<script src="/js/jquery-2.1.1.js"></script>
<script src="/js/iCheck/icheck.min.js"></script>
<script type="text/javascript">
    $(function(){
        wx.config({
            debug: false,
            appId: '{$jsSign["appid"]}',
            timestamp: {$jsSign['timestamp']},
            nonceStr: '{$jsSign["noncestr"]}',
            signature: '{$jsSign["signature"]}',
            jsApiList: ['closeWindow']
        });
        wx.ready(function () {
            $("#signIn").on("click",function(){

                var name = $("input[name='name']").val();
                var unit = $("input[name='unit']").val();
                var mobile = $("input[name='mobile']").val();
                var gender = $("input[name='gender']:checked").val();
                var data = ({
                    name : name,
                    mobile : mobile,
                    gender : gender,
                    unit : unit
                });
                if(!name){
                    $("input[name='name']").focus();
                    isTop("请填写姓名");
                    return false;
                } else if(!mobile){
                    $("input[name='mobile']").focus();
                    isTop("请填写手机号");
                    return false;
                } else if(!unit){
                    $("input[name='unit']").focus();
                    isTop("请输入单位名称");
                    return false;
                } else {
                    if(isNaN(mobile) || !CheckPhone(mobile)) {
                        $("input[name='mobile']").focus();
                        isTop("手机号有误");
                        return false;
                    }
                }

                $.ajax({
                    type:"post",
                    url:"{:Url('Index/register')}",
                    data:data,
                    success:function(msg){
                        if(msg['code'] == 1){
                            isTop("关注成功,请返回企业号", true);
                            wx.closeWindow();
                        } else {
                            isTop(msg['msg']);
                        }
                    }
                });
            });
        });
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

    });
    function CheckPhone(phone){
        var reg = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
        if (reg.test(phone)) {
            return true;
        } else {
            return false;
        }
    }
    function isTop(msg, close){
        $("#isTop").text(msg);
        $("#isTop").animate({"top":"5px"},400);
        setTimeout(function(){
            $("#isTop").animate({"top":"-100px"},400);
            if(close){
                wx.closeWindow();
            }
        },5000);
    }
</script>
</body>
</html>